package com.mi.rabbit;

import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

public class RabbitHouse {


	private Set<Rabbit> rabbits = new CopyOnWriteArraySet<Rabbit>();
	
	public RabbitHouse() {
		addRabbit(new Rabbit(1, this));
	}
	
	public void addRabbit(Rabbit rabbit){
		rabbits.add(rabbit);
	}
	
	
	public void removeRabbit(Rabbit rabbit){
		rabbits.remove(rabbit);
	}
	
	
	public int getTotalRabbitCount(int currentMonth){
		for(int i=1;i<=currentMonth;i++){
			Iterator<Rabbit> it = rabbits.iterator();
			while(it.hasNext()){
				Rabbit rabbit = it.next();
				rabbit.giveBirth(i);
				rabbit.die(i);
			}
		}
		return rabbits.size();
	}
	
}
